/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package events.pose;

import gui.SnazzySpritesGUI;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import snazzysprites.SnazzySprites;
import state.Pose;
import state.SnazzySpritesState;
import state.SnazzySpritesStateManager;
import state.Sprite;

/**
 * Handles the selection of a pose in the current animation
 * @author Andrew Gratta <andrew.gratta@stonybrook.edu>
 */
public class SelectPoseHandler implements ListSelectionListener{

    @Override
    public void valueChanged(ListSelectionEvent e) {
        if (!e.getValueIsAdjusting())
        {
            SnazzySprites singleton = SnazzySprites.getSnazzySprites();
            SnazzySpritesStateManager manager = singleton.getStateManager();
            SnazzySpritesGUI gui = singleton.getGUI();
            int index = gui.getSelectedPoseIndex();
            if (index == -1)
            {
                return;
            }
            Sprite sprite = manager.getSprite();
            Pose pose = sprite.getCurrentAnimation().getPose(index);
            sprite.setPose(pose);
            manager.setState(SnazzySpritesState.SELECT_SHAPE_STATE);
            manager.getZoomableCanvasState().updatePoseArea();
            gui.getPoseDurationField().setText(pose.getDuration() + "");
        }
    }
    
}
